package com.trade.wzj.common.yang;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.trade.wzj.model.xiang.ClientInfo;
import com.trade.wzj.service.yang.ClientInfoService_Yang;

@Controller
@RequestMapping("/ClientContrillerYang")
public class ClientController_Yang {

	@Resource(name = "clientInfo")
	private ClientInfoService_Yang clientInfoService;

	public ClientInfoService_Yang getClientInfoService() {
		return clientInfoService;
	}

	public void setClientInfoService(ClientInfoService_Yang clientInfoService) {
		this.clientInfoService = clientInfoService;
	}

	@RequestMapping("clientSel")
	@ResponseBody
	public PageInfo<ClientInfo> clientSel(@RequestParam(value="name",required=false)String name, @RequestParam(value="currentPages",required=false)Integer currentPages, Model model) {
		// 起始页数
		Integer currentPage = 1;
		// 每条显示的行数
		int rowPerPage = 5;
		PageInfo<ClientInfo> pageInfo = null;
		// 结果集列表
		List<ClientInfo> list = null;
		try {
			if (null != currentPages) {
				// 页码不为空时，将当前页信息赋值
				currentPage = currentPages;
			}
			PageHelper.startPage(currentPage, rowPerPage);
			list = clientInfoService.clientMhSel(name);
			System.out.println(list);
			pageInfo = new PageInfo<>(list);
			
			System.out.println(pageInfo.getList());
			for (ClientInfo clientInfo : list) {
				System.out.println(clientInfo);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pageInfo;
	}
	
	@RequestMapping("/getClientInfoById")
	@ResponseBody
	public ClientInfo getClientInfoById(Integer id) {
		ClientInfo info=null;
		try {
			info=clientInfoService.getClientInfoById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return info;
	}
	
	//通过id修改客户基本信息
	@RequestMapping("/updateClientInfoById")
	@ResponseBody
	public boolean updateClientInfoById(ClientInfo client) {
		boolean bol=false;
		try {
			clientInfoService.updateClientInfoById(client);
			bol=true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bol;
	}
}
